import java.awt.DisplayMode;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Window;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;

import javax.swing.JFrame;


@SuppressWarnings("serial")
public class NarwhalScreen extends JFrame {
	
	private GraphicsDevice vc;
	private DisplayMode screenStandard;
	private DisplayMode narwhalStandard;
	
	public NarwhalScreen(){
		GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
		vc = ge.getDefaultScreenDevice();
		screenStandard = vc.getDisplayMode();
		narwhalStandard = new DisplayMode(1024, 768, DisplayMode.BIT_DEPTH_MULTI, DisplayMode.REFRESH_RATE_UNKNOWN);
		
		setFullScreen();
		
		addFocusListener(new Focus());
		
		setUndecorated(true);
		setResizable(false);
		vc.setFullScreenWindow(this);
	}
	
	public void setFullScreen(){
		if (vc.isDisplayChangeSupported()) {
			vc.setDisplayMode(narwhalStandard);
		}
	}
	
	public void restoreScreen() {
		if (vc.isDisplayChangeSupported()) {
			vc.setDisplayMode(screenStandard);
		}
	}
	
	
	
	private class Focus implements FocusListener {

		@Override
		public void focusGained(FocusEvent arg0) {
			setFullScreen();
		}

		@Override
		public void focusLost(FocusEvent arg0) {
			restoreScreen();
		}
		
	}
}
